package cn.lingyangwl.agile.infra.gen.service.impl;

import cn.lingyangwl.agile.infra.gen.assembly.GenTableAssembly;
import cn.lingyangwl.agile.infra.gen.manager.GenTableColumnManager;
import cn.lingyangwl.agile.infra.gen.model.entity.GenTableColumn;
import cn.lingyangwl.agile.infra.gen.model.rqrs.GenTableColumnResp;
import cn.lingyangwl.agile.infra.gen.service.GenTableColumnService;
import cn.lingyangwl.framework.tool.core.exception.BizException;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author shenguangyang
 */
@Service
public class GenTableColumnServiceImpl implements GenTableColumnService {
    @Resource
    private GenTableColumnManager genTableColumnManager;
    @Resource
    private GenTableAssembly genTableAssembly;

    @Override
    public List<GenTableColumnResp> listGenTableColumnByTableId(Long tableId) {
        List<GenTableColumn> list = genTableColumnManager.listByTableId(tableId);
        return list.stream().map(genTableAssembly::toGenTableColumnRS).collect(Collectors.toList());
    }

    @Override
    public void deleteGenTableColumnByIds(List<Long> ids) {
        if (!genTableColumnManager.removeByIds(ids)) {
            throw new BizException("删除失败");
        }
    }
}
